home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / mel / mel-u.el.z / mel-u.el
Encoding:
Text File  |  1998-05-21  |  3.8 KB  |  121 lines

  1. ;;; mel-u.el: uuencode encoder/decoder for GNU Emacs
  2.  
  3. ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
  4.  
  5. ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
  6. ;; Created: 1995/10/25
  7. ;; Version: $Id: mel-u.el,v 5.10 1997/07/14 21:47:48 morioka Exp $
  8. ;; Keywords: uuencode
  9.  
  10. ;; This file is part of MEL (MIME Encoding Library).
  11.  
  12. ;; This program is free software; you can redistribute it and/or
  13. ;; modify it under the terms of the GNU General Public License as
  14. ;; published by the Free Software Foundation; either version 2, or (at
  15. ;; your option) any later version.
  16.  
  17. ;; This program is distributed in the hope that it will be useful, but
  18. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20. ;; General Public License for more details.
  21.  
  22. ;; You should have received a copy of the GNU General Public License
  23. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  24. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  25. ;; Boston, MA 02111-1307, USA.
  26.  
  27. ;;; Code:
  28.  
  29. (require 'emu)
  30. (require 'mel)
  31.  
  32.  
  33. ;;; @ variables
  34. ;;;
  35.  
  36. (defvar uuencode-external-encoder '("uuencode" "-")
  37.   "*list of uuencode encoder program name and its arguments.")
  38.  
  39. (defvar uuencode-external-decoder
  40.   (list "sh" "-c" (format "(cd %s; uudecode)" mime-temp-directory))
  41.   "*list of uuencode decoder program name and its arguments.")
  42.  
  43.  
  44. ;;; @ uuencode encoder/decoder for region
  45. ;;;
  46.  
  47. (defun uuencode-external-encode-region (start end)
  48.   "Encode current region by unofficial uuencode format.
  49. This function uses external uuencode encoder which is specified by
  50. variable `uuencode-external-encoder'."
  51.   (interactive "*r")
  52.   (save-excursion
  53.     (as-binary-process (apply (function call-process-region)
  54.                   start end (car uuencode-external-encoder)
  55.                   t t nil (cdr uuencode-external-encoder))
  56.                )
  57.     ;; for OS/2
  58.     ;;   regularize line break code
  59.     (goto-char (point-min))
  60.     (while (re-search-forward "\r$" nil t)
  61.       (replace-match "")
  62.       )
  63.     ))
  64.  
  65. (defun uuencode-external-decode-region (start end)
  66.   "Decode current region by unofficial uuencode format.
  67. This function uses external uuencode decoder which is specified by
  68. variable `uuencode-external-decoder'."
  69.   (interactive "*r")
  70.   (save-excursion
  71.     (let ((filename (save-excursion
  72.               (save-restriction
  73.             (narrow-to-region start end)
  74.             (goto-char start)
  75.             (if (re-search-forward "^begin [0-9]+ " nil t)
  76.                 (if (looking-at ".+$")
  77.                 (buffer-substring (match-beginning 0)
  78.                           (match-end 0))
  79.                   ))))))
  80.       (if filename
  81.       (as-binary-process
  82.        (apply (function call-process-region)
  83.           start end (car uuencode-external-decoder)
  84.           t nil nil (cdr uuencode-external-decoder))
  85.        (setq filename (expand-file-name filename mime-temp-directory))
  86.        (as-binary-input-file (insert-file-contents filename))
  87.        ;; The previous line causes the buffer to be made read-only, I
  88.        ;; do not pretend to understand the control flow leading to this
  89.        ;; but suspect it has something to do with image-mode. -slb
  90.        ;;    Use `inhibit-read-only' to avoid to force
  91.        ;;    buffer-read-only nil. - tomo.
  92.        (let ((inhibit-read-only t))
  93.          (delete-file filename)
  94.          )
  95.        ))
  96.       )))
  97.  
  98. (defalias 'uuencode-encode-region 'uuencode-external-encode-region)
  99. (defalias 'uuencode-decode-region 'uuencode-external-decode-region)
  100.  
  101.  
  102. ;;; @ uuencode encoder/decoder for file
  103. ;;;
  104.  
  105. (defun uuencode-insert-encoded-file (filename)
  106.   "Insert file encoded by unofficial uuencode format.
  107. This function uses external uuencode encoder which is specified by
  108. variable `uuencode-external-encoder'."
  109.   (interactive (list (read-file-name "Insert encoded file: ")))
  110.   (call-process (car uuencode-external-encoder) filename t nil
  111.         (file-name-nondirectory filename))
  112.   )
  113.  
  114.  
  115. ;;; @ end
  116. ;;;
  117.  
  118. (provide 'mel-u)
  119.  
  120. ;;; mel-u.el ends here
  121.